<template>

    <div id="largePage" class="large-container">
        <a-spin tip="Loading..." :spinning="loading">

            <div class="page-main">
                <div id="pageMap" class="page-map"></div>
                <div class="page-title">
                    <img class="page-title-bg" src="@/assets/large/large-title1.png" />
                    <div class="page-title-main">
                        <div class="title-left">
                            <div class="title-time">
                                <div style="font-size:18px;margin-right:20px">{{timeStr}}</div>
                                <div>{{dateStr}} {{weekStr}}</div>
                            </div>
                        </div>
                        <div class="title-mid"> </div>
                        <div class="title-right">
                            <div style="display:flex;align-items: center;margin: 0 20px;">
                                <span>晴</span>
                                <span class="sun-ico iconfont">&#xe615;</span>
                                <span style="font-size:18px">6~10℃</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="page-left" :key="'left_'+renderKey">
                    <div class="agency-name">{{pageData.organizationInfo?pageData.organizationInfo.name:'--'}}</div>
                    <Left1Vue :pageData="pageData.organizationJobStats || {}" />
                    <Left2Vue :pageData="pageData.patientCountInfo || {}" />
                    <Left3Vue :pageData="pageData.dailyPatientData || []" :organizationInfo="pageData.organizationInfo"/>
                </div>

                <div class="page-right" :key="'right_'+renderKey">
                    <Right1Vue :pageData="pageData.organizationInfo || {}"/>
                    <Right2Vue :pageData="pageData.patientAgeAnalysis || {}"/>
                    <Right3Vue :pageData="pageData.couponStatistics || {}"/>
                </div>

            </div>
        </a-spin>
    </div>

</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { format, getStorageUserInfo, mapLoad } from "@/utils";
import Left1Vue from "./panel/left1.vue";
import Left2Vue from "./panel/left2.vue";
import Left3Vue from "./panel/left3.vue";
import Right1Vue from "./panel/right1.vue";
import Right2Vue from "./panel/right2.vue";
import Right3Vue from "./panel/right3.vue";
import largeApi from "@/api/largeApi";
let largeMap: any = null;
@Component({
    name: "home",
    components: { Left1Vue, Left2Vue, Left3Vue, Right1Vue, Right2Vue, Right3Vue },
})
export default class extends Vue {
    loading = false;
    timeStr = "";
    dateStr = "";
    weekStr = "";
    timer: any = null;
    async mounted() {
        // 如果是平台端，进入后提示并跳转到平台端大屏
        // const userInfo = getStorageUserInfo();
        // if (userInfo.type === "PLATFORM") {
        //     this.$router.replace({ name: "largeScreen" });
        //     return;
        // }
        this.getTimeStr();
        await this.getData();
        this.timer = setInterval(this.getTimeStr, 1000);

        this.mapInit();

        window.addEventListener("resize", this.handleResize);
    }
    renderKey = 1;
    handleResize() {
        // 添加防抖处理（300ms
        if (this.resizeTimer) {
            clearTimeout(this.resizeTimer);
        }

        this.resizeTimer = setTimeout(() => {
            this.renderKey++;
        }, 300);
    }
    resizeTimer: number | null = null;

    beforeDestroy() {
        this.timer && clearInterval(this.timer);
         window.removeEventListener('resize',this.handleResize)
    }
    getTimeStr() {
        const nowTime = new Date();
        this.timeStr = format(nowTime, "hh:mm:ss");
        this.dateStr = format(nowTime, "yyyy-MM-dd");
        const dayOfWeek = nowTime.getDay();
        // 转换为星期名称
        const weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
        this.weekStr = weekdays[dayOfWeek];
    }
    pageData:any = {};
    async getData() {
        this.loading = true;
        try {
            // 如果有id 需要传入id
            const aid=this.$route.query.id || ''

            const res = await largeApi.getBigScreenData({organizationId:aid});
            this.pageData = res.data;
            const typeCodeObj={
                "中医馆":'zy',
                "体检中心":'tj',
                "社区医院":'sq',
                "养老中心":'yl',
                "口腔门诊":'kq',
            }
            const organizationInfo=res.data.organizationInfo
            this.testList=[
                {
                    name:organizationInfo.name,
                    type:organizationInfo.institutionalType,
                    typeCode:typeCodeObj[organizationInfo.institutionalType] || 'zy',
                    num:res.data.patientCountInfo.patientCount,
                    hospitalSite:organizationInfo.hospitalSite
                }
            ]
        } finally {
            this.loading = false;
        }
    }
    markerArr: any[] = [];
    markerShowIdx = 0;
    testList:any[] = [];
    setMarkerStr(item) {
        let markerStr = `<div class="large-marker large-marker-${item.typeCode}">`;
        markerStr += `<div class="large-marker-top"><img class="large-marker-img" src="/img/map-${item.typeCode}.png" /><span class="large-marker-title">${item.name}</span></div>`;
        markerStr += `</div>`;

        let markerShowStr = `<div class="large-marker large-marker-${item.typeCode}">`;
        markerShowStr += `<div class="large-marker-top"><img class="large-marker-img" src="/img/map-${item.typeCode}.png" /><span class="large-marker-title">${item.name}</span></div>`;
        markerShowStr += `<div class="marker-content">`;
        markerShowStr += `<div class="content-list"><span class="content-title">类型：</span><span class="content-info">${item.type}</span></div>`;
        markerShowStr += `<div class="content-list"><span class="content-title">就诊人数：</span><span class="content-info">${item.num}人</span></div>`;
        markerShowStr += `<div class="content-list"><span class="content-title">地址：</span><span class="content-info">${item.hospitalSite}</span></div>`;
        markerShowStr += `</div>`;
        markerShowStr += `</div>`;
        return { markerStr, markerShowStr };
    }
    mapInit() {
        mapLoad(() => {
            if (largeMap) {
            } else {
                const lnglat=JSON.parse(this.pageData?.organizationInfo?.siteCoordinate || '')
                largeMap = new AMap.Map("pageMap", {
                    zoom: 18,
                    center: [lnglat.longitude,lnglat.latitude],
                    layers: [
                        // 设置地图图层
                        new AMap.TileLayer.Satellite(), // 卫星图层
                    ],
                });

                this.testList.forEach((item, i) => {
                    const { markerStr, markerShowStr } = this.setMarkerStr(item);
                    const markerContent = new AMap.Marker({
                        map: largeMap,
                        position: [lnglat.longitude,lnglat.latitude],
                        content: markerStr,
                        offset: new AMap.Pixel(0, 0),
                    });
                    markerContent.on("click", (e) => {
                        markerContent.setContent(markerShowStr);
                        if (this.markerShowIdx === i) return;
                        this.markerArr[this.markerShowIdx].marker.setContent(this.markerArr[this.markerShowIdx].markerStr);
                        this.markerShowIdx = i;
                    });

                    this.markerArr.push({ marker: markerContent, markerStr, markerShowStr });
                });
                largeMap && largeMap.setFitView();
            }
        });
    }
}
</script>
<style lang="scss">
.large-container {
    width: 100%;
    height: 100%;
    position: relative;
    background-color: #161b27;
    min-width: 1360px;
    min-height: 765px;
    #pageMap {
        height: 100%;
        width: 100%;
    }
    .page-bg {
        height: 100%;
        width: 100%;
        display: block;
        z-index: 1;
    }
    .page-title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #fff;
        font-size: 16px;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        z-index: 10;
        .page-title-bg {
            width: 100%;
            max-height: 12vh;
        }
        .page-title-main {
            position: absolute;
            left: 0;
            top: 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
            width: 100%;
            height: 100%;
            padding: 0 15px;
        }

        .title-left {
            display: flex;
            align-items: center;
            width: 25%;
            padding-top: 4vh;

            .title-time {
                text-align: right;
                padding-right: 20px;
                margin: 0 20px;
                display: flex;
                align-items: center;
            }
        }
        .title-mid {
            font-size: 34px;
            text-shadow: 0px 2px 14px rgba(0, 0, 0, 0.5);
            width: 50%;
            text-align: center;
            padding-bottom: 20px;
            font-style: italic;
            letter-spacing: 2px;
        }
        .title-right {
            padding-top: 4vh;
            width: 25%;
            display: flex;
            justify-content: end;
            font-size: 14px;
            .sun-ico {
                color: #fdcf03;
                font-size: 26px;
                margin: 0 10px;
            }
        }
    }
    // .page-title::after{
    //     content: '';
    //     position: absolute;
    //     width: 100px;
    //     height: 100%;
    //     left: 0;
    //     top: 0;
    //     background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0) 100%);
    //     transform: skew(30deg);
    // }
    .page-main {
        height: 100vh;
        width: 100%;
        display: flex;
        flex-direction: column;
        position: relative;
        z-index: 1;
    }
    .agency-name {
        background: linear-gradient(to bottom, #fff 0%, #fff 40%, #92dfd7 60%, #92dfd7 100%);
        background-clip: text;
        color: transparent;
        font-weight: bold;
        font-style: italic;
        font-size: 30px;
        padding-top: 20px;
        padding-left: 30px;
    }
    .page-left {
        height: 100%;
        width: 25%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        flex-shrink: 0;
        padding: 15px 10px;
        position: absolute;
        left: 0;
        top: 0;
        padding-top: 10vh;
        overflow: hidden;
        background: linear-gradient(90deg, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.7) 50%, rgba(0, 0, 0, 0.1) 100%);
    }
    .page-mid {
        width: 50%;
        display: flex;
        padding: 10px;
        position: absolute;
        left: 25%;
        top: 12vh;
    }
    .page-right {
        height: 100%;
        width: 25%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        flex-shrink: 0;
        padding: 15px 10px;
        position: absolute;
        right: 0;
        top: 0;
        padding-top: 10vh;
        overflow: hidden;
        background: linear-gradient(-90deg, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0.7) 50%, rgba(0, 0, 0, 0.1) 100%);
    }

    .mid-box {
        background-color: rgba(41, 159, 145, 0.3);
        display: flex;
        align-items: center;
        border-radius: 8px;
        .mid-list {
            padding: 10px 20px;
            margin-right: 40px;
        }
        .mid-title {
            font-size: 16px;
            color: #3ad3c1;
            font-weight: bold;
        }
        .mid-val {
            font-size: 34px;
            color: #ffffff;
            text-shadow: 0px 0px 4px #3ad3c1;
        }
    }
    .panel-title {
        position: relative;
        font-size: 22px;
        letter-spacing: 4px;
    }
    .panel-title-bg {
        height: 80px;
         animation: titleAnimation 1s linear infinite alternate ;
    }
    .right-title .panel-title-box {
        padding-left: 50px;
    }
    .right-title .panel-title-bg {
        transform: rotateY(180deg);
    }
    .panel-title-box {
        position: absolute;
        left: 0;
        top: 18px;
        background: linear-gradient(to bottom, #fff 0%, #fff 30%, #92dfd7 100%);
        background-clip: text;
        color: transparent;
        width: 100%;
        height: 30px;
        display: flex;
        align-items: center;
        padding: 0 20px;
        font-weight: bold;
        font-style: italic;
    }
    .panel-title-ico {
        margin-right: 15px;
    }
    /* 自定义整个滚动条 */
    ::-webkit-scrollbar {
        width: 2px; /* 设置滚动条的宽度 */
    }

    /* 自定义滚动条轨道 */
    ::-webkit-scrollbar-track {
        background: rgba(100, 100, 100, 0.2); /* 设置轨道的背景颜色 */
    }

    /* 自定义滚动条的滑块（thumb） */
    ::-webkit-scrollbar-thumb {
        background: rgba(68, 187, 255, 0.7); /* 设置滑块的背景颜色 */
    }

    /* 当滑块悬停或活动时自定义滚动条的滑块 */
    ::-webkit-scrollbar-thumb:hover {
        background: #555; /* 设置滑块在悬停状态下的背景颜色 */
    }

    .large-modal {
        .ant-modal {
            padding-bottom: 0;
        }

        .ant-modal-wrap {
            display: flex;
            align-items: center;
        }
        .ant-modal-content {
            background-color: rgba(8, 56, 50, 0.7);
            border: solid 1px rgba(56, 205, 187, 1);
            border-radius: 10px;
        }
        .ant-modal-body {
            padding: 15px;
        }
        .ant-modal-close-x {
            height: 40px;
            width: 40px;
            line-height: 40px;
        }
        .ant-modal-close:focus,
        .ant-modal-close:hover {
            color: #48e2fb;
        }
    }

    .large-marker {
        width: max-content;
        padding: 5px 10px;
        border-radius: 4px;
        font-size: 14px;
        color: #fff;
        position: relative;
        transform: translateX(-50%) translateY(calc(-100% - 15px));
    }
    .large-marker::after {
        content: "";
        width: 20px;
        height: 15px;
        clip-path: polygon(0% 0%, 50% 100%, 100% 0%);
        transform: translateX(-50%);
        position: absolute;
        bottom: -15px; /* 三角形高度 */
        left: 50%;
    }
    .large-marker-top {
        display: flex;
        align-items: center;
        font-size: 16px;
    }

    .large-marker-zy {
        background-color: rgba(58, 211, 193, 0.4);
        border: 1px solid #3ad3c1;
    }
    .large-marker-zy::after {
        background-color: rgba(58, 211, 193, 0.4);
        border: 1px solid #3ad3c1;
    }
    .large-marker-tj {
        background-color: rgba(121, 198, 255, 0.4);
        border: 1px solid rgba(121, 198, 255, 1);
    }
    .large-marker-tj::after {
        background-color: rgba(121, 198, 255, 0.4);
        border: 1px solid rgba(121, 198, 255, 1);
    }
    .large-marker-sq {
        background-color: rgba(24, 175, 250, 0.4);
        border: 1px solid rgba(24, 175, 250, 1);
    }
    .large-marker-sq::after {
        background-color: rgba(24, 175, 250, 0.4);
        border: 1px solid rgba(24, 175, 250, 1);
    }
    .large-marker-yl {
        background-color: rgba(255, 207, 10, 0.4);
        border: 1px solid rgba(255, 207, 10, 1);
    }
    .large-marker-yl::after {
        background-color: rgba(255, 207, 10, 0.4);
        border: 1px solid rgba(255, 207, 10, 1);
    }
    .large-marker-kq {
        background-color: rgba(199, 57, 242, 0.4);
        border: 1px solid rgba(199, 57, 242, 1);
    }
    .large-marker-kq::after {
        background-color: rgba(199, 57, 242, 0.4);
        border: 1px solid rgba(199, 57, 242, 1);
    }
    .marker-content {
        padding: 10px;
    }
    .content-list {
    }
    .large-marker-title {
    }
    .large-marker-img {
        width: 20px;
        height: 20px;
    }

    .large-select {
        width: 200px;
        color: #fff;
        .ant-select-selection {
            border-color: rgba(58, 211, 193, 1) !important;
            background-color: rgba(58, 211, 193, 0.1);
        }
        .ant-select-arrow {
            color: #fff;
        }
    }

    .large-input {
        border-color: rgba(58, 211, 193, 1) !important;
        background-color: rgba(58, 211, 193, 0.1);
        color: #fff;
    }
    .large-search {
        .ant-input {
            border-color: rgba(58, 211, 193, 1) !important;
            background-color: rgba(58, 211, 193, 0.1);
            color: #fff;
        }
        .ant-input-search-icon,
        .ant-input-clear-icon {
            color: #fff;
        }
    }

    .child-title {
        font-size: 18px;
        color: #ffffff;
        background: linear-gradient(90deg, #3ad3c1 0%, rgba(58, 211, 193, 0.1) 66%, rgba(58, 211, 193, 0) 100%);
        border-radius: 0px 0px 0px 16px;
        display: inline-block;
        min-width: 350px;
        padding: 2px 15px;
    }

    .child-content-title {
        display: flex;
        align-items: center;
        font-size: 16px;
        color: #3ad3c1;
        font-weight: bold;
    }
    .child-content-titleico {
        width: 20px;
        margin-right: 5px;
    }

    .large-table {
        .ant-table-thead > tr > th {
            background-color: rgba(58, 211, 193, 0.3);
            color: #3ad3c1;
        }
        .ant-table-thead > tr > th:first-child,
        .ant-table-tbody > tr > td:first-child {
            border-left: solid 1px rgba(255, 255, 255, 0.2);
        }
        .ant-table-tbody > tr > td {
            color: rgba(255, 255, 255, 1);
        }
        .ant-table-thead > tr > th,
        .ant-table-tbody > tr > td {
            padding: 8px 8px;
            border-bottom: unset;
        }
        .ant-table-bordered .ant-table-thead > tr > th,
        .ant-table-bordered .ant-table-tbody > tr > td {
            border-right: solid 1px rgba(255, 255, 255, 0.2);
        }
        .ant-table-bordered .ant-table-body > table {
            border: unset;
            border-bottom:solid 1px rgba(255, 255, 255, 0.2);
        }
        .ant-table-bordered .ant-table-header > table{
            border: unset;
            border-top:solid 1px rgba(255, 255, 255, 0.2);
        }
        .even-row {
            background-color: rgba(255, 255, 255, 0.1);
        }
        .ant-table-tbody > tr:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected) > td {
            background-color: rgba(47, 72, 163, 0.3);
        }

        .ant-pagination-item {
            background-color: rgba(58, 211, 193, 0.2);
            border: unset;
        }
        .ant-pagination-item a {
            color: rgba(255, 255, 255, 0.7);
        }
        .ant-pagination-item-active {
            background-color: rgba(58, 211, 193, 0.5);
        }
        .ant-pagination-item-active a {
            color: #fff !important;
        }

        .ant-pagination-prev .ant-pagination-item-link,
        .ant-pagination-next .ant-pagination-item-link {
            border: unset;
            background-color: rgba(58, 211, 193, 0.2);
        }
        .ant-pagination-prev a,
        .ant-pagination-next a {
            color: #fff;
        }
        .ant-pagination-disabled a {
            color: rgba(255, 255, 255, 0.7);
        }

        .ant-pagination-jump-prev .ant-pagination-item-container .ant-pagination-item-ellipsis,
        .ant-pagination-jump-next .ant-pagination-item-container .ant-pagination-item-ellipsis {
            color: rgba(255, 255, 255, 0.7);
        }

        .ant-table-fixed-header > .ant-table-content > .ant-table-scroll > .ant-table-body,
        .ant-table-fixed-header > .ant-table-content > .ant-table-scroll > .ant-table-header {
            background-color: transparent;
        }

        .ant-table-hide-scrollbar,
        .ant-table-fixed-header .ant-table-scroll .ant-table-header {
            overflow: hidden !important;
            margin-bottom: 0px !important;
            padding-bottom: 0px !important;
        }

        .ant-table-bordered.ant-table-empty .ant-table-placeholder{
            border-right:1px solid rgba(255,255,255,0.3);
            border-left:1px solid rgba(255,255,255,0.3);
            border-top:1px solid rgba(255,255,255,0.3);
            border-bottom:1px solid rgba(255,255,255,0.3)
        }
        .ant-table-placeholder{
            background-color: transparent;
        }
        .ant-empty-description{
            color: #3ad3c1;
        }
    }
}

@keyframes titleAnimation {
    from {
        opacity: 0.5;
    }
    to {
        opacity: 1;
    }
}
</style>
